function reauthLoad() {
	document.getElementById('blog_title').innerHTML = feedJson.rss.channel[0].title;
	document.getElementById('blog_desc').innerHTML = feedJson.rss.channel[0].description;
	reauthLoadPosts();
}

function reauthLoadPosts() {
	var entriesList = new dojo.dnd.Source("blog_entries_list");
	
	function createDiv(className, value) {
		var tmpDiv = document.createElement("div");
		tmpDiv.className = className;// + " dojoDndItem";
		if (value) tmpDiv.innerHTML = value;
		return tmpDiv;
	}
	
	for (var i=0; i<feedJson.rss.channel[0].item.length; i++) {
		var currPost = feedJson.rss.channel[0].item[i];
		var postDiv = createDiv("blog_post");
		
		//create a sub div b/c dojo will overwrite the id of a dnd element
		var postSubDiv = document.createElement("div");
		postSubDiv.id = "post_" + i;
		postDiv.appendChild(postSubDiv);
		
		//note- this order is referenced elsewhere - this will be fixed later
		postSubDiv.appendChild( createDiv("blog_post_title", currPost.title) );
		postSubDiv.appendChild( createDiv("blog_post_pubDate", currPost.pubDate) );
		postSubDiv.appendChild( createDiv("blog_post_description", currPost.description) );
		postSubDiv.appendChild( createDiv("blog_post_category", currPost.category) );
		postSubDiv.appendChild( createDiv("blog_post_link", currPost.link) );
		postSubDiv.appendChild( createDiv("blog_post_edit", "<a href=\"javascript:reauthEdit('" + postSubDiv.id + "')\">Edit</a>") );
		
		//document.getElementById('blog_entries_list').appendChild(postDiv);
		entriesList.insertNodes(false, [postDiv]);
	}
}

function reauthEdit(postId) {
	console.log('postId: ' + postId);
	var currPost = document.getElementById(postId);
	
	//right now we can edit the title, desc
	
	//enter new data - include postId
	document.getElementById("edit_form_title").value = currPost.childNodes[0].innerHTML;
	document.getElementById("edit_form_content").value = currPost.childNodes[2].innerHTML;
	document.getElementById("edit_form_post_id").value = currPost.id;
	
	//display edit menu and enable save button
	document.getElementById("edit_post_form").style.display = "block";
	document.getElementById("save_edits").style.display = "inline";
}

function reauthSave() {
	var currPost = document.getElementById( document.getElementById("edit_form_post_id").value );
	currPost.childNodes[0].innerHTML = document.getElementById("edit_form_title").value;
	currPost.childNodes[2].innerHTML = document.getElementById("edit_form_content").value;
	
	//hide save and menu
	document.getElementById("edit_post_form").style.display = "none";
	document.getElementById("save_edits").style.display = "none";

	//clear old data
	document.getElementById("edit_form_title").value = '';
	document.getElementById("edit_form_content").value = '';
}

function reauthPublish() {
	
	var htmlTop = 
		"<html>\
			<head>\
				<style type='text/css'>\
					body {line-height: 1.4em; margin: 1em auto; padding: 40px; font-size: 18px; font-family: Arial,Helvetica,sans-serif;}\
					h1 {font-size: 1.2em; font-family: 'Arial Black',Gadget,sans-serif; }\
					hr {}\
					.blog_post_title {font-size: 1.1em; font-weight: bold;}\
					.blog_post_description {margin-bottom: 50px;}\
					.blog_post_category, .blog_post_link, .blog_post_edit, .blog_post_pubDate {display: none;}\
				</style>\
			</head>\
			<body>";
	var htmlBottom = "</body></html>";
	var blogTitleHtml = "<h1 id='blog_title'>" + feedJson.rss.channel[0].title + "</h1>";
	var blogSubTitleHtml = "<h3 id='blog_subtitle'>" + feedJson.rss.channel[0].description + "</h3>";
	var blogContentHtml = "";
	
	//set title
	var chapterList = document.getElementById('book_structure_list');
	for (var i=0; i<chapterList.childNodes.length; i++) {
		if (!chapterList.childNodes[i].innerHTML) continue;
		console.log(chapterList.childNodes[i].innerHTML);
		blogContentHtml += chapterList.childNodes[i].innerHTML;
	}
	
	var finalHtml = htmlTop + blogTitleHtml + blogSubTitleHtml + "<hr>" + blogContentHtml + htmlBottom;
	
	//send the form
	var form = document.getElementById('publish_form');
	document.getElementById('ppw_save_page_field').value = finalHtml;
	form.submit();
	
	
//	document.getElementById('testingta').value = finalHtml;
}